#include<stdio.h>
int leapcheck(int a);
int whichday(int y,int m,int d);
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int y,m,d;
		scanf("%d%d%d",&y,&m,&d);
		printf("%d\n",whichday(y,m,d));
	}
	return 0;
}
int whichday(int y,int m,int d)
{
	int count=0;
	switch(m)
	{
		case 12:
		case 11:
			count++;
		case 10:
		case 9:
			count++;
		case 8:
			count++;
		case 7:
		case 6:
			count++;
		case 5:
		case 4:
			count++;
		case 3:
			count--;
			if(!leapcheck(y))
				count--;
		case 2:
			count++;
		case 1:
			break;
	}
	count+=(m-1)*30;
	count+=d;
	return count;
}
int leapcheck(int a)
{
	if(a%4==0&&a%100!=0)
		return 1;
	else if(a%400==0)
		return 1;
	else
		return 0;
}
